package com.example.prom.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dangwen1
 * @date 2021年08月12日 21:05
 * @description
 */
@Getter
public class ExcelListener<T> extends AnalysisEventListener<T> {

    List<T> dataList = new ArrayList<>();
    Map<Integer, String> headMap = new HashMap<>();

    @Override
    public void invoke(T t, AnalysisContext analysisContext) {
//        Integer rowIndex = analysisContext.readSheetHolder().getApproximateTotalRowNumber();
//        System.out.println("rowIndex:"+rowIndex);
        dataList.add(t);
    }

//    @Override
//    public void invokeHead(Map<Integer, CellData> headMap, AnalysisContext context) {
//        super.invokeHead(headMap, context);
////        System.out.println(context.readRowHolder().getRowIndex());
////        Set<Map.Entry<Integer, CellData>> entries = headMap.entrySet();
////        for (Map.Entry<Integer, CellData> entry : entries){
////            System.out.println("key: "+entry.getKey());
////            System.out.println("value: "+entry.getValue());
////        }
////        System.out.println("invokeHead--------------------------------");
//    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        this.headMap = headMap;
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        for (T t : dataList){
//            System.out.println(t.toString());
        }
    }
}
